package com.financing.platform.service.impl;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.financing.platform.dao.IUserInfoDao;
import com.financing.platform.dto.UserInfoDTO;
import com.financing.platform.service.IUserInfoService;
import com.financing.platform.util.SecureUtil;
import com.financing.platform.util.StringUtil;
import com.financing.platform.vo.LicashiCountVO;
import com.financing.platform.vo.LicashiDetailVO;

@Service("userInfoServiceImpl")
@Component("userInfoServiceImpl")
public class UserInfoServiceImpl extends BaseServiceImpl implements IUserInfoService{

	@Autowired
	private IUserInfoDao userInfoDaoImpl;
	
	public UserInfoDTO queryUserInfo(UserInfoDTO userInfoDTO) {
		return userInfoDaoImpl.queryUserInfo(userInfoDTO);
	}

	public boolean userLogin(UserInfoDTO userInfoDTO) {
		if(StringUtil.isNullOrEmptyStr(userInfoDTO.getUserNickname())||StringUtil.isNullOrEmptyStr(userInfoDTO.getPassword())){
			return false;
		}
		userInfoDTO.setUserType("02");
		userInfoDTO.setStatus("0");
		userInfoDTO.setPassword(SecureUtil.MD5EncryptAndBase64(userInfoDTO.getPassword()));
		UserInfoDTO userInfo = userInfoDaoImpl.queryUserInfo(userInfoDTO);
		if(userInfo != null && userInfo.getUserId() != null){
			return true;
		}
		return false;
	}

	public UserInfoDTO addUserInfo(UserInfoDTO userInfoDTO) {
		userInfoDTO.setPassword(SecureUtil.MD5EncryptAndBase64(userInfoDTO.getPassword()));
		return userInfoDaoImpl.addUserInfo(userInfoDTO);
	}

	public UserInfoDTO updateUserInfo(UserInfoDTO userInfoDTO) {
		if(userInfoDTO.getPassword() != null && !userInfoDTO.getPassword().equals("")){
			userInfoDTO.setPassword(SecureUtil.MD5EncryptAndBase64(userInfoDTO.getPassword()));
		}
		userInfoDTO = userInfoDaoImpl.updateUserInfo(userInfoDTO);
		userInfoDTO.setPassword(null);
		return userInfoDTO;
	}

	public List<UserInfoDTO> queryAllUserInfo(UserInfoDTO userInfoDTO) {
		return userInfoDaoImpl.queryAllUserInfo(userInfoDTO);
	}

	@Override
	public List<LicashiCountVO> querylcsstatistics(Map<String,String> map) throws SQLException {
		return userInfoDaoImpl.querylcsstatistics(map);
	}

	@Override
	public Map<String, String> querymanstatistics(Map<String,String> map) throws SQLException {
		return userInfoDaoImpl.querymanstatistics(map);
	}

	@Override
	public List<LicashiDetailVO> querylcsDetailstatistics(
			Map<String, String> map) throws SQLException {
		 List<LicashiDetailVO> querylcsDetailstatistics = userInfoDaoImpl.querylcsDetailstatistics(map);
		 return querylcsDetailstatistics;
	}

	@Override
	public int countlcsDetailstatistics(Map<String, String> map)
			throws SQLException {
		return userInfoDaoImpl.countlcsDetailstatistics(map);
	}

	@Override
	public List<String> queryUserInfoSubUserId(String systemUserId)
			throws SQLException {
		return userInfoDaoImpl.queryUserInfoSubUserId(systemUserId);
	}

	@Override
	public List<Map<String, Object>> queryVistDetail(Map<String, Object> map) throws SQLException {
		return userInfoDaoImpl.queryVistDetail(map);
	}

	@Override
	public Map<String,String> queryUserPhoneByManagerLCS(
			Map<String, Object> map) throws SQLException {
		return userInfoDaoImpl.queryUserPhoneByManagerLCS(map);
	}

}
